package com.fand.manager.controller;


import java.util.List;

import javax.annotation.Resource;

import com.fand.common.util.ResultHelp;
import com.fand.manager.model.rolemenu.SysRoleMenuPostDTO;
import com.fand.manager.model.rolemenu.SysRoleMenuTreeDTO;
import com.fand.manager.service.ISysRoleMenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import io.swagger.annotations.Api;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 角色菜单表 前端控制器
 * </p>
 *
 * @author javaboy
 * @since 2021-06-10
 */
@Api(tags = "角色菜单表")
@RestController
@RequestMapping("/sys-role-menu")
public class SysRoleMenuController {

    @Resource
    private ISysRoleMenuService sysRoleMenuService;

    @ApiOperation("根据id查询角色")
    @PreAuthorize("hasAuthority('sys:role:menu')")
    @GetMapping("/findRoleTree")
    public ResultHelp<List<SysRoleMenuTreeDTO>> findRoleTree(@RequestParam Long id){
        return ResultHelp.success(sysRoleMenuService.findRoleTree(id));
    }

    @ApiOperation("保存授权")
    @PreAuthorize("hasAuthority('sys:role:menu')")
    @PostMapping("/save")
    public ResultHelp<List<SysRoleMenuTreeDTO>> save(@RequestBody SysRoleMenuPostDTO sysRoleMenuPostDTO){
        return ResultHelp.success(sysRoleMenuService.save(sysRoleMenuPostDTO));
    }
}

